import win32gui, win32ui, win32con, win32api, win32com
import win32api
import _winapi as api
import win32print
import time
from PIL import Image
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import *
import win32gui
import sys
import pyautogui

if __name__ == '__main__':
    handle = win32gui.FindWindow(0, "原神")
    win32gui.SendMessage(handle, win32con.WM_SYSCOMMAND, win32con.SC_RESTORE, 0)  # 这句很重要，这句可以保证将句柄置到前端
    win32gui.SetForegroundWindow(handle)
    x, y, x1, y1 = win32gui.GetWindowRect(handle)
    time.sleep(0.1)
    print(x,y,x1,y1)
    print(x1-x,y1-y)
    img = pyautogui.screenshot(region=[x+3, y+32, x1-x-6, y1-y-35])  # x,y,w,h
    img.show()
    print(img.size)
